package math.base;

/**
 * @author Saga
 *
 */
public class Point3d {
    public Point3d() {
        this.coord = new Coord3d(0.0, 0.0, 0.0);
    }

    public Point3d(final Coord3d _coord) {
        this.coord = _coord;
    }

    public Point3d(final double _x, final double _y, final double _z) {
        this.coord = new Coord3d(_x, _y, _z);
    }

    public final void init(final double _x, final double _y, final double _z) {
        this.coord.init(_x, _y, _z);
    }

    public final void setCoord(final Coord3d _coord) {
        this.coord = _coord;
    }

    public final Coord3d getCoord() {
        return this.coord;
    }

    public final void setCoord(final int _id, final double _val) {
        this.coord.setCoord(_id, _val);
    }

    public final double getCoord(final int _id) {
        return this.coord.getCoord(_id);
    }

    public final void setX(final double _x) {
        this.coord.setX(_x);
    }

    public final double getX() {
        return this.getCoord().getX();
    }

    public final void setY(final double _y) {
        this.coord.setY(_y);
    }

    public final double getY() {
        return this.getCoord().getY();
    }

    public final void setZ(final double _z) {
        this.coord.setZ(_z);
    }

    public final double getZ() {
        return this.getCoord().getZ();
    }

    //compare
    public final boolean isEqual(final Point3d _pt, final double _distTol) {
        return this.calcSquareDistanceTo(_pt) <= _distTol * _distTol;
    }

    //add
    public final void add(final Vector3d _vec) {
        this.coord.add(_vec.getCoord());
    }

    public final Point3d added(final Vector3d _vec) {
        return new Point3d(this.coord.added(_vec.getCoord()));
    }

    //subtract
    public final void subtract(final Vector3d _vec) {
        this.coord.subtract(_vec.getCoord());
    }

    public final Point3d subtracted(final Vector3d _vec) {
        return new Point3d(this.coord.subtracted(_vec.getCoord()));
    }

    public final Vector3d subtracted(final Point3d _pt) {
        return new Vector3d(this.coord.subtracted(_pt.getCoord()));
    }

    //distance
    public final double calcDistanceTo(final Point3d _pt) {
        return this.coord.subtracted(_pt.getCoord()).calcMagnitude();
    }

    public final double calcSquareDistanceTo(final Point3d _pt) {
        return this.coord.subtracted(_pt.getCoord()).calcSquareMagnitude();
    }

    @Override
    public Point3d clone() {
        return new Point3d(this.coord.clone());
    }

    private Coord3d coord;
}
